<template>
  <div class="dialog" v-show="visible">
    <div class="dialog-wrap">
      <div class="dialog-header">
        <slot name="header"></slot>
        <span class="dialog-header-close" @click="$emit('update:visible',false)">X</span>
      </div>
      <div class="dialog-body">
        <slot></slot>
      </div>
      <div class="dialog-footer">
        <slot name="footer"></slot>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Dialog",
  props: {
    visible: {
      type:Boolean,
      require:true
    }
  },
  watch: {
    visible:{
      immediate:true, // 开启立即监听
      handler(){
        if(this.visible){
          document.documentElement.style.overflow = 'hidden'
        }else {
          document.documentElement.style.overflow = 'auto'
        }
      }
    }
  }
};
</script>

<style lang="less" scoped>
.dialog {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.3);
  .dialog-wrap {
    width: 430px;
    height: 230px;
    background-color: #fff;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    padding: 20px;
    box-sizing: border-box; /**内减模式 */
    .dialog-header {
      font-size: 18px;
      display: flex;
      justify-content: space-between;
      .dialog-header-close {
        font-size: 14px;
        cursor: pointer;
        color: #ccc;
        &:hover {
          color: #409eff;
        }
      }
    }
    .dialog-body {
      // height: 120px;
      // line-height: 120px;
      // padding-top: 46px;
      text-align: center;
      font-size: 18px;
    }
  }
}
</style>